<template>

    <view class="item-wrap" style="margin-bottom: 0">
      <view style="display: flex;justify-content: space-between;align-items: center">
        <uni-section title="保费合计" type="line"/>

        <view style="text-align: right;color: red;padding-right: 20rpx">
          <text v-if="type === 1">
            {{ handleTotalPrice(ruleForm) }}
          </text>
          <text v-if="type === 2">
            {{ handleTotal(ruleForm.insuranceVoList) }}
          </text>
        </view>
      </view>
    </view>

</template>

<script>
export default {
  name: 'totalExpense',
  props: {
    value: {
      type: Object,
      default: {},
    },
    type:{
      type:Number,
      default: 0,
    }
  },
  computed: {
    ruleForm: {
      get() {
        let that = this;
        const proxy = new Proxy(that.value, {
          get(target, key) {
            return Reflect.get(target, key);
          },
          set(target, key, value) {
            that.$emit("input", {...target, [key]: value});
            return true;
          },
        });
        return proxy;
      },
    },
    handleTotalPrice() {
      return function (val) {
        let num = 0,
            numR = 0
        num = Math.round(Number(val.jqxAmount) * 100) +
            Math.round(Number(val.carTax) * 100) +
            Math.round(Number(val.syxAmount) * 100) +
            Math.round(Number(val.otherInsuranceSumAmount) * 100)
        numR = (val.carCount * num / 100).toFixed(2)
        this.$set(this.value, 'totalPrice', numR)
        this.$set(this.ruleForm, 'totalPrice', numR)
        return numR
      }
    },
    handleTotal() {
      return function (val) {
        let numL = 0,
            sum = 0,
            numR = 0
        for (let i = 0; i < val.length; i++) {

          numL = Math.round(Number(val[i].jqxAmount) * 100) +
              Math.round(Number(val[i].carTax) * 100) +
              Math.round(Number(val[i].syxAmount) * 100) +
              Math.round(Number(val[i].otherInsuranceSumAmount) * 100)

          sum += numL
        }
        numR = (sum / 100).toFixed(2)
        this.$set(this.value, 'totalPrice', numR)
        this.$set(this.ruleForm, 'totalPrice', numR)
        return numR
      }
    }
  },
  watch: {},
  data() {
    return {};
  },
  created() {
  },
  mounted() {
  },
  methods: {},
};
</script>

<style scoped lang=""></style>


